/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import type { StringObjType } from '@/components/_pages/AmountApply/index.d';
import { checkAndTriggerRefresh } from '@/components/_pages/red-point/_utils';
import request from '@/utils/request';
import { message } from 'antd';

export async function getWkdInvoiceList(params: StringObjType, fromRedDot?: boolean): Promise<any> {
  const { current, ...rest } = params;
  return request('/InvoiceManage/invoiceList', {
    method: 'POST',
    data: { page: current, ...rest },
  }).then(checkAndTriggerRefresh(getWkdInvoiceList, fromRedDot));
}

export async function getStationInvoiceList(
  params: StringObjType,
  fromRedDot?: boolean,
): Promise<any> {
  const { current, ...rest } = params;
  console.info('getStationInvoiceList', params);
  return request('/invoice/applicantsData', {
    method: 'POST',
    data: { page: current, ...rest },
  }).then(checkAndTriggerRefresh(getStationInvoiceList, fromRedDot));
}

export async function openInvoiceServe(params: {
  id?: string;
  invoice_id?: string;
  callback: () => void;
}): Promise<any> {
  const { callback, ...rest } = params;
  return request('/OpenInvoiceDo/gdInvoice', {
    method: 'POST',
    data: { ...rest },
  }).then(({ code, msg }) => {
    if (code == 0) {
      message.info('成功');
    } else {
      message.error(msg);
    }
    callback();
    return { code };
  });
}

export async function deleteInvoiceOrder(params: {
  id?: string;
  invoice_id?: string;
  callback: () => void;
}): Promise<any> {
  const { callback, ...rest } = params;
  return request('/InvoiceManage/deleteInvoiceOrder', {
    method: 'POST',
    data: { ...rest },
  }).then(({ code, msg }) => {
    if (code == 0) {
      message.info('成功');
    } else {
      message.error(msg);
    }
    callback();
    return { code };
  });
}

export async function openInvoiceMutil(params: StringObjType): Promise<any> {
  return request('/OpenInvoiceDo/multiGdInvoice', {
    method: 'POST',
    data: { ...params },
  });
}

export async function getInvoiceTitle(params: StringObjType): Promise<any> {
  return request('/invoice/getShopInfo', {
    method: 'POST',
    data: { ...params },
  });
}

export async function getGDinvoice(params: { id: string; callback: () => void }): Promise<any> {
  const { id, callback } = params;
  return request('/OpenInvoice/gdInvoice', {
    method: 'POST',
    data: { id },
  }).then(({ code, msg }) => {
    if (code == 0) {
      message.info('成功');
    } else {
      message.error(msg);
    }
    callback();
    return { code };
  });
}
export async function getApplicantUpdate(params: {
  id: string;
  status?: number;
  admin_commnet?: string;
  waybill_no?: string;
  callback: () => void;
}): Promise<any> {
  const { callback, ...rest } = params;
  return request('/invoice/applicantUpdate', {
    method: 'POST',
    data: { ...rest },
  }).then(({ code, msg }) => {
    if (code == 0) {
      message.info('成功');
    } else {
      message.error(msg);
    }
    callback();
    return { code };
  });
}
